package net.lab1024.sa.admin.module.business.roland.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.admin.module.business.roland.dao.RolandPerformanceTypeDao;
import net.lab1024.sa.admin.module.business.roland.domain.entity.RolandPerformanceTypeEntity;
import net.lab1024.sa.admin.module.business.roland.domain.form.RolandPerformanceTypeAddForm;
import net.lab1024.sa.admin.module.business.roland.domain.form.RolandPerformanceTypeQueryForm;
import net.lab1024.sa.admin.module.business.roland.domain.form.RolandPerformanceTypeUpdateForm;
import net.lab1024.sa.admin.module.business.roland.domain.vo.PerformanceTypeSelectVO;
import net.lab1024.sa.admin.module.business.roland.domain.vo.RolandPerformanceTypeVO;
import net.lab1024.sa.common.common.domain.PageResult;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.common.common.util.SmartBeanUtil;
import net.lab1024.sa.common.common.util.SmartPageUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 演出类型表 Service
 *
 * @Author dragon
 * @Date 2023-12-11 13:27:12
 * @Copyright dragon
 */

@Service
public class RolandPerformanceTypeService {

    @Autowired
    private RolandPerformanceTypeDao rolandPerformanceTypeDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<RolandPerformanceTypeVO> queryPage(RolandPerformanceTypeQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<RolandPerformanceTypeVO> list = rolandPerformanceTypeDao.queryPage(page, queryForm);
        PageResult<RolandPerformanceTypeVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(RolandPerformanceTypeAddForm addForm) {
        RolandPerformanceTypeEntity rolandPerformanceTypeEntity = SmartBeanUtil.copy(addForm, RolandPerformanceTypeEntity.class);
        rolandPerformanceTypeDao.insert(rolandPerformanceTypeEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(RolandPerformanceTypeUpdateForm updateForm) {
        RolandPerformanceTypeEntity rolandPerformanceTypeEntity = SmartBeanUtil.copy(updateForm, RolandPerformanceTypeEntity.class);
        rolandPerformanceTypeDao.updateById(rolandPerformanceTypeEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)) {
            return ResponseDTO.ok();
        }

        rolandPerformanceTypeDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id) {
            return ResponseDTO.ok();
        }

        rolandPerformanceTypeDao.deleteById(id);
        return ResponseDTO.ok();
    }

    public ResponseDTO<List<PerformanceTypeSelectVO>> queryAll() {
        List<PerformanceTypeSelectVO> list = rolandPerformanceTypeDao.selectAll();
        return ResponseDTO.ok(list);
    }
}
